package com.hotelvip.common.utils;

import com.hotelvip.common.utils.enumconfig.BaseEnum;

/**
 * @author Lzh
 * @date 2020/12/11 14:31
 */

public class EnumUtil {
    /**
     * 1.Class<T> enumClass枚举类
     * 2.<T extends CodeEnum>对枚举的说明，enumClass需要继承CodeEnum,才能调用each.getByindex()方法
     * @param index
     * @param enumClass
     * @param <T>
     * @return
     */
    public  static <T extends BaseEnum>T getByindex(Integer index, Class<T> enumClass)
    {
        for (T each: enumClass.getEnumConstants())
        {
            if(index.equals(each.getIndex()))
            {
                return each;
            }
        }
        return null;
    }
    /**
     * 1.Class<T> enumClass枚举类
     * 2.<T extends CodeEnum>对枚举的说明，enumClass需要继承CodeEnum,才能调用each.getByindex()方法
     * @param name
     * @param enumClass
     * @param <T>
     * @return
     */
    public  static <T extends BaseEnum>T getByName(String name, Class<T> enumClass)
    {
        for (T each: enumClass.getEnumConstants())
        {
            if(name.equals(each.getName()))
            {
                return each;
            }
        }
        return null;
    }

}
